package com.woniuxy.meal.controller.consumer;


import com.woniuxy.meal.entity.DietOrder;
import com.woniuxy.meal.entity.DietOrderLog;
import com.woniuxy.meal.form.message.OrderLogMessage;
import com.woniuxy.meal.service.DietOrderLogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;


@Component
@RocketMQMessageListener(consumerGroup = "log",topic = "orders_log")
public class OrderLogConsumer implements RocketMQListener<OrderLogMessage> {

    @Autowired
    private DietOrderLogService dietOrderLogService;


    @Override
    public void onMessage(OrderLogMessage message) {
        System.out.println("开始记录订单日志");
        DietOrderLog dietOrderLog = new DietOrderLog();
        dietOrderLog.setOrderNum(message.getOrderNum());
        dietOrderLog.setOrderState(message.getOrderState());
        dietOrderLog.setOperReason(message.getOperReason());
        dietOrderLog.setOperUser(message.getOperUser());
        dietOrderLog.setOperDate(LocalDateTime.now());
        dietOrderLog.setOperContent(message.getOperContent());
        dietOrderLogService.save(dietOrderLog);
    }
}
